package com.zhdl.instruction.analysis;

import com.project.command.faq.analysis.ComAnalysis;
import com.project.command.faq.analysis.ComAnalysisData;
import com.project.command.faq.analysis.ComAnalysisResult;
import io.netty.buffer.ByteBuf;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 示例: 自定义通信解析
 * service必须写上协议名, 与数据库protocols表中一致
 *
 * @Description:
 * @author: liu zhenming
 * @date: 2023/7/20 16:03
 */
@Slf4j
@Service(CustomAnalysisImpl.CUSTOM_ANALYSIS)
public class CustomAnalysisImpl implements ComAnalysis<CustomBusResp, ByteBuf> {

    public static final String CUSTOM_ANALYSIS = "custom_demo";

    @Override
    public ComAnalysisResult<CustomBusResp> analysisData(ComAnalysisData<ByteBuf> data) {

        List<CustomBusResp> demoList = new ArrayList<>();
        demoList.add(new CustomBusResp());

        //如果返回的ComAnalysisResult<List> 中的list大于0,则代表本次拆包解包完整. 否则继续监听数据,直到完整
        return new ComAnalysisResult<>(demoList);
    }

    /**
     * 11 为发送数据
     *
     * @return /
     */
    @Override
    public String getHeadAnalysis() {
        return "11";
    }

    @Override
    public byte[] getAfterAnalysis(String cmdStr) {
        return (getHeadAnalysis() + cmdStr).toLowerCase().getBytes();
    }


}
